import CreateDatabase from "../components/databaseInfo.vue"
import { metadataCovert, metaDefaultConfg } from "./constant"
class ResourceConn {
  constructor(opt, params) {
    this.opt = opt;
    this.params = params
    this.node = params.node;
  }

  getMetadataConfig() {
    return {
      buildScript: () => {
        return 'PRAGMA database_list'
      },
      rowCovert: (d, row) => {
        			const {
        				connId
        			} = this.node.data.properties
        d.name = row.name;
        d.id = `${connId}_${d.name}`;
        d.type = 'CATALOG';
        d.properties.catalog = d.name;
        d.properties.pluginId = 'sqlite'

      },
      covert: (res) => {
        return metadataCovert(this.opt, this.getMetadataConfig().rowCovert, res, this.node)
      }
    }
  }

  getContextMenus() {
    let menus = [];
    const disabled = this.node && this.node.childrenLoaded;
    menus.push({
      label: "新建数据库",
      dividedTop: true,
      disabled: !disabled,
      click: (event, item) => {
        this.opt.bus.$emit(this.opt.config.CONTEXT_MENU_EVENT_KEY, {
          type: this.opt.config.CONTEXT_MENU_TYPE_DIALOG,
          title: '新建数据库',
          width: '350px',
          height: '300px',
          component: CreateDatabase,
          data: {
            connId: this.node.data.properties.connId,
            //charsets: characterSets

          }
        })
        return true;
      },
    })
    menus.push({
      label: "新建查询",
      click: () => {
        this.opt.bus.$emit(this.opt.config.CONTEXT_MENU_EVENT_KEY, {
          type: this.opt.config.CONTEXT_MENU_TYPE_TAGS_COM,
          title: '新建查询',
          id: this.node.data.id + "_sql_query",
          component: 'WorkbeanchSqlEditor',
          data: {
            connId: this.node.data.properties.connId,
            catalog: this.node.data.properties.catalog
          }
        })
        return true;
      },
    })
    return menus
  }
}

export {
  ResourceConn
}